require.config({
    paths: {
        'jquery': ['http://cdn.bootcss.com/jquery/2.2.4/jquery.min', '/js/lib/jquery.min'],
        'doT': '/js/lib/doT.min',
        'select2': '/js/lib/select2.min',
        'bootstrap': '/js/lib/bootstrap.min'
    },
    shim: {
        'bootstrap': ['jquery']
    }
});

var myFun = {};
require(['jquery', 'doT', 'select2', 'common', 'bootstrap'], function($, doT, select2, common) {
    $(function() {
        function initSchool() {
            $.get(common.urlBase + "/school/allSchool.json", function(data, statu) {
                data = eval('(' + data + ')');
                var schools = data.data;
                var schoolTmpl = doT.template($('#template_school').text());
                $('#school').html(schoolTmpl(schools));
                $('#school').select2();
            });
        }
        initSchool();


        $('.sidebar ul li').each(function() {
            if ($(this).text() == '查看堂主') {
                $(this).parent().css('display', 'block');
                $(this).children().css('color', '#46A3FF');
            }
        });


        $('#add_master').submit(function() {
            var account = $('#account').val();
            var pwd = $('#pwd').val();
            var name = $('#master_name').val();
            var genderID = $('input:radio:checked').attr('id');
            var school_id = $('#school option:selected').val();
            var phone = $('#phone').val();
            var email = $('#email').val();
            var role = 2;
            var gender = genderID == 'female' ? 2 : 1;
            var data = {
                'name': name,
                'gender': gender,
                'school_id': school_id,
                'account': account,
                'password': pwd,
                'phone': phone,
                'email': email,
                'role': role
            };

            $.post(common.urlBase + '/account/add.json', data, function(data, statu) {
                data = eval('(' + data + ')');
                if (data['ok']) {
                    $('#noticeMsg').text('添加堂主成功！');
                    $('#noticeModal').modal('show');
                    window.location = '/views/master.html';
                } else {
                    $('#noticeMsg').text(data['message']);
                    $('#noticeModal').modal('show');
                }
            });
            return false;
        });
    });


});
